package events;

import java.util.Random;

import simulation.Echeancier;
import simulation.StationState;


import lois.Poisson;


/**
 * Arrivee.
 */
public class WelcomeEvent extends Event {

	public static double NB_SKIEUR_TOTAL;
	
	// 100/3600 en moyenne donc lambda = 36
	private static Poisson poisson_9_11 = new Poisson(36);
	// 50/3600 en moyenne donc lambda = 360/5 = 72
	private static Poisson poisson_11_13 = new Poisson(72);
	
	@Override
	public String toString() {
		return "Un nouveau skieur arrive dans la station [T="+Echeancier.toHour(date)+"]";
	}

	@Override
	public void treat(Echeancier e) {
		NB_SKIEUR_TOTAL++;
		
		Event event = new WelcomeEvent();
		Event next;
		
		if(date < Echeancier.T14H30){
			
			if( (date >=  Echeancier.T9H && date <  Echeancier.T11H) || (date >=  Echeancier.T13H && date <  Echeancier.T14H) )
				event.date = date+poisson_9_11.next();
			else
				event.date = date+poisson_11_13.next();
				
			//Les skieurs arrivent!
			int rand = (new Random()).nextInt(10);
			if (rand==0){
				//Le skieur remonte par D
				
				next = new EndWaitTeleSkiD();
				next.date = 10+date+(10*StationState.WD);
				StationState.WD++;
			}else{
				if(StationState.WB < StationState.WC){
					next = new EndWaitTeleSkiB();
					next.date = 10+date+(10*StationState.WB);
					StationState.WB++;
				}else{
					next = new EndWaitTeleSkiC();
					next.date = 10+date+(10*StationState.WC);
					StationState.WC++;
				}
			}
			e.ajouter(next);
			e.ajouter(event);
		}
		
	}

}
